<?php defined('IN_NWIDC') or exit('Access Invalid!');?>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<style>
  #ui-datepicker-div{
    z-index: 100000 !important;
  }
</style>
<?php
  $m = Model('setting');
  $config = $m->getListSetting();
?>
<div class="wrap">
  <div class="tabmenu">
    <ul class="tab pngFix">
      <li class="active"><a href="index.php?act=member_order">销售统计</a></li>
      <li class='normal'>
      <a href="">
      总共销售<span style='color:red;padding:0 5px;'><?php echo $output['total_amount'];?></span>元，共计盈利<span style='color:red;padding:0 5px;'><?php echo $output['margin']?></span>元
      </a>
      </li>
      <li>
        <?php
           $task = Model();
            $tasks_num = $task->table('proxy_task')->field("count(*) as num")->where(array('member_id' => $_SESSION['member_id']))->find();
        ?>
        <a href="javascript:;" onclick='$("#task_table").parent().slideToggle()'>
          查看销售任务(<?php echo $tasks_num['num']?>)
        </a>
      </li>
      </ul>
  </div>
  <style>
    #task_table td,#task_table th{
      text-align: center;
      line-height: 35px;
    }
    #task_table tr{
      border-collapse: collapse;
      border : 1px solid #ddd;
    }
    #task_table thead tr{
      border-top: 0;
    }
  </style>
  <div style='display:none'>
  <table width='100%' id='task_table'>
      <thead>
        <th>
          任务编号
        </th>
        <th>
          起始时间
        </th>
        <th>
          结束时间
        </th>
        <th>
          完成金额 / 任务金额
        </th>
        <th>
          任务状态
        </th>
        
      </thead>
      <?php
              $task->cls();
              $tasks = $task->table('proxy_task')->where(array('member_id' => $_SESSION['member_id']))->select();
              foreach($tasks as $t){
            ?>
            <tr>
            <td>
              <?php echo $t['id']?>
            </td>
            <td>
              <?php echo date('Y-m-d H:i:s',$t['start_time'])?>
            </td>
            <td>
              <?php echo date('Y-m-d H:i:s',$t['end_time'])?>
            </td>
            <td>
              ￥<?php
                $task->cls();
                $total = $task->table("order")->field(array('sum(order_amount) as total'))->where(
                  array(
                    "add_time" => array('between',"{$t['start_time']},{$t['end_time']}"),
                    'buyer_id' => $t['member_id'],
                    'order_state' => 40
                  )
                )->find();
                echo $total = ($total['total'] ? $total['total'] : 0);
              ?>
              /
              ￥<?php
                echo $t['money'];
              ?>
            </td>
            <td>
              <?php 
                $time = time();
                if($time > $t['end_time']){
                  if($total > $t['money']){
                    echo '已完成';
                  }
                  else{
                    echo '未完成';
                  }
                }
                elseif($time < $t['start_time']){
                  echo '任务未开始';
                }
                else{
                  echo '进行中';
                }
              ?>

            </td>
            
            </tr>
            <?php    
              }
            ?>
  </table>
  </div>

  <form method="get" action="index.php" target="_self">
    <table class="ncm-search-table">
      <input type="hidden" name="act" value="member_proxy" />
      <input type="hidden" name='op' value='statistics'>
      <input type="hidden" name= "recycle" value="<?php echo $_GET['recycle'];?>" />
      <tr>
        <td>&nbsp;</td>
        <th><input type='checkbox' name='seeme' value='1' <?php if($_GET['seeme']){ echo 'checked'; }?> style='vertical-align: -1px;'></th>
        <td class="w100">只看我的销售</td>
        <th><?php echo $lang['member_order_time'];?></th>
        <td class="w240"><input type="text" class="text w70" name="query_start_date" id="query_start_date" value="<?php echo $_GET['query_start_date']; ?>"/><label class="add-on"><i class="icon-calendar"></i></label>&nbsp;&#8211;&nbsp;<input type="text" class="text w70" name="query_end_date" id="query_end_date" value="<?php echo $_GET['query_end_date']; ?>"/><label class="add-on"><i class="icon-calendar"></i></label></td>
        <th><?php echo $lang['member_order_sn'];?></th>
        <td class="w160"><input type="text" class="text w150" name="order_sn" value="<?php echo $_GET['order_sn']; ?>"></td>
        <th>用户名</th>
        <td class="w160"><input type="text" class="text w150" name="member_name" value="<?php echo $_GET['member_name']; ?>"></td>
        <td class="w70 tc"><label class="submit-border">
            <input type="submit" class="submit" value="<?php echo $lang['nc_search'];?>"/>
          </label></td>
      </tr>
    </table>
  </form>
  <table class="ncm-default-table order">
    <thead>
      <tr>
        <th class="w10"></th>
        <th colspan="2">商品</th>
        <th class="w100">单价（元）</th>
        <th>代理价</th>
        <?php
        
          if($config['open_tax'] == 1){
        ?>
        <th>
        行邮税
        </th>
        <?php    
          }
        ?>
        <th>盈利</th>
        <th class="w40">数量</th>
        <th class="w120">订单金额</th>
        <th class="w100">交易状态</th>
      </tr>
    </thead>
    <?php if ($output['order_group_list']) { ?>
    <?php foreach ($output['order_group_list'] as $order_pay_sn => $group_info) { ?>
    <?php $p = 0;?>
    <tbody order_id="" <?php if (!empty($group_info['pay_amount']) && $p == 0) {?> class="pay" <?php }?>>
      <?php foreach($group_info['order_list'] as $order_id => $order_info) {?>
      <?php if (empty($group_info['pay_amount'])) {?>
      <tr>
        <td colspan="19" class="sep-row"></td>
      </tr>
      <?php }?>
      <?php if (!empty($group_info['pay_amount']) && $p == 0) {?>
      <tr>
        <td colspan="19" class="sep-row"></td>
      </tr>
      <tr>
        <td colspan="19" class="pay-td"><span class="ml15">在线支付金额：<em>￥<?php echo ncPriceFormat($group_info['pay_amount']);?></em></span> </td>
      </tr>
      <?php }?>
      <?php $p++;?>
      <tr>
        <th colspan="19"> <span class="ml10">
          <!-- order_sn -->
          <?php echo $lang['member_order_sn'].$lang['nc_colon'];?><?php echo $order_info['order_sn']; ?>
          <?php if ($order_info['order_from'] == 2){?>
          <i class="icon-mobile-phone"></i>
          <?php }?>
          </span>
          <!-- order_time -->
          <span><?php echo $lang['member_order_time'].$lang['nc_colon'];?><?php echo date("Y-m-d H:i:s",$order_info['add_time']); ?></span>

          <!-- store_name -->
          <span><a href="<?php echo urlShop('show_store','index',array('store_id'=>$order_info['store_id']), $order_info['extend_store']['store_domain']);?>" title="<?php echo $order_info['store_name'];?>"><?php echo $order_info['store_name']; ?></a></span>

          <span>
            下单人：<?php $m = Model('member'); $user = $m->find($order_info['buyer_id']); echo $user['member_name']; ?>
          </span>

          <!-- QQ -->
          <span member_id="<?php echo $order_info['extend_store']['member_id'];?>">
          <?php if(!empty($order_info['extend_store']['store_qq'])){?>
          <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=<?php echo $order_info['extend_store']['store_qq'];?>&site=qq&menu=yes" title="QQ: <?php echo $order_info['extend_store']['store_qq'];?>"><img border="0" src="http://wpa.qq.com/pa?p=2:<?php echo $order_info['extend_store']['store_qq'];?>:52" style=" vertical-align: middle;"/></a>
          <?php }?>

          <!-- wang wang -->
          <?php if(!empty($order_info['extend_store']['store_ww'])){?>
          <a target="_blank" href="http://amos.im.alisoft.com/msg.aw?v=2&uid=<?php echo $order_info['extend_store']['store_ww'];?>&site=cntaobao&s=2&charset=<?php echo CHARSET;?>"  class="vm" ><img border="0" src="http://amos.im.alisoft.com/online.aw?v=2&uid=<?php echo $order_info['extend_store']['store_ww'];?>&site=cntaobao&s=2&charset=<?php echo CHARSET;?>" alt="Wang Wang"  style=" vertical-align: middle;"/></a>
          <?php }?>
          </span>




        </th>
      </tr>

      <!-- S 商品列表 -->
      <?php $i = 0;?>
      <?php foreach ($order_info['goods_list'] as $k => $goods_info) {?>
      <?php $i++;?>
      <tr>
        <td class="bdl"></td>
        <td class="w70"><div class="ncm-goods-thumb"><a href="<?php echo $goods_info['goods_url'];?>" target="_blank"><img src="<?php echo $goods_info['image_60_url'];?>" onMouseOver="toolTip('<img src=<?php echo $goods_info['image_240_url'];?>>')" onMouseOut="toolTip()"/></a></div></td>
        <td class="tl"><dl class="goods-name">
            <dt><a href="<?php echo $goods_info['goods_url'];?>" target="_blank"><?php echo $goods_info['goods_name']; ?></a></dt>
            <?php if (!empty($goods_info['goods_type_cn'])) { ?>
            <dd><span class="sale-type"><?php echo $goods_info['goods_type_cn'];?></span></dd>
            <?php } ?>
          </dl></td>
        <td><?php echo $goods_info['source_price'];?></td>
        <td>
          <?php 
            if(empty($goods_info['goods_proxy']) || !$goods_info['goods_proxy']){
              echo $goods_info['goods_price'];
            }
            else{
              echo $goods_info['goods_proxy'];
            }

            ?>
        </td>
          <?php
            if($config['open_tax'] == 1){
          ?>
        <td>
            <?php echo $goods_info['tax'] ? $goods_info['tax'] : '无'?>
        </td>
          <?php
            }
          ?>
        <td>
          <?php echo $goods_info['margin']?>
        </td>
        <td><?php echo $goods_info['goods_num']; ?></td>


        <!-- S 合并TD -->
        <?php if (($order_info['goods_count'] > 1 && $k ==0) || ($order_info['goods_count'] == 1)){?>
        <td class="bdl" rowspan="<?php echo $order_info['goods_count'];?>"><p class=""><strong><?php echo $order_info['order_amount']; ?></strong></p>
          <p class="goods-freight">
            <?php if ($order_info['shipping_fee'] > 0){?>
            (<?php echo $lang['member_order_shipping_han'];?>运费<?php echo $order_info['shipping_fee'];?>)
            <?php }else{?>
            <?php echo $lang['nc_common_shipping_free'];?>
            <?php }?>
          </p>
          <p title="<?php echo $lang['member_order_pay_method'].$lang['nc_colon'];?><?php echo $order_info['payment_name']; ?>"><?php echo $order_info['payment_name']; ?></p></td>
        <td class="bdl" rowspan="<?php echo $order_info['goods_count'];?>"><p><?php echo $order_info['state_desc']; ?> <?php echo $order_info['evaluation_status'] ? $lang['member_order_evaluated'] : '';?></p>

          <!-- 订单查看 -->

        </td>
   
        <!-- E 合并TD -->
        <?php } ?>
      </tr>

      <!-- S 赠品列表 -->

      <?php if (!empty($order_info['zengpin_list']) && $i == count($order_info['goods_list'])) { ?>
      <tr>
        <td class="bdl"></td>
        <td colspan="5" class="tl"><div class="ncm-goods-gift"> 赠品：
            <ul>
              <?php foreach ($order_info['zengpin_list'] as $zengpin_info) { ?>
              <li><a title="赠品：<?php echo $zengpin_info['goods_name'];?> * <?php echo $zengpin_info['goods_num'];?>" href="<?php echo $zengpin_info['goods_url'];?>" target="_blank"><img src="<?php echo $zengpin_info['image_60_url'];?>" onMouseOver="toolTip('<img src=<?php echo $zengpin_info['image_240_url'];?>>')" onMouseOut="toolTip()"/></a></li>
              <?php } ?>
            </ul>
          </div></td>
      </tr>
      <?php } ?>
      <!-- E 赠品列表 -->

      <?php } ?>
      <!-- E 商品列表 -->

      <?php } ?>
    </tbody>
    <?php } ?>
    <?php } else { ?>
    <tbody>
      <tr>
        <td colspan="20" class="norecord"><div class="warning-option"><i>&nbsp;</i><span><?php echo $lang['no_record'];?></span></div></td>
      </tr>
    </tbody>
    <?php } ?>
    <?php if($output['order_pay_list']) { ?>
    <tfoot>
      <tr>
        <td colspan="19"><div class="pagination"> <?php echo $output['show_page']; ?> </div></td>
      </tr>
    </tfoot>
    <?php } ?>
  </table>
</div>
<script charset="utf-8" type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js" ></script>
<script charset="utf-8" type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/sns.js" ></script>
<script type="text/javascript">
$(function(){
    $('#query_start_date').datepicker({dateFormat: 'yy-mm-dd'});
    $('#query_end_date').datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
